<template>
  <div>
    <el-row>
      <el-card class="box-card" shadow="never">
        <div slot="header" class="clearfix">
          <span>订单总览</span>
        </div>
        <div class="wapper">
          <el-badge :value="3" class="item">
            <el-button round size="large"> 待生产产品数</el-button>
          </el-badge>
          <el-badge :value="3" class="item">
            <el-button round size="large"> 生产中产品数</el-button>
          </el-badge>
          <el-badge :value="3" class="item">
            <el-button round size="large"> 生产完成产品数</el-button>
          </el-badge>
          <el-badge :value="12" class="item">
            <el-button round size="large"> 待排产品数</el-button>
          </el-badge>
          <el-badge :value="3" class="item">
            <el-button round size="large"> 排产中产品数</el-button>
          </el-badge>
          <el-badge :value="1" class="item" type="primary">
            <el-button round size="large"> 已延期订单数</el-button>
          </el-badge>
          <el-badge :value="2" class="item" type="warning">
            <el-button round size="large"> 延期产品数</el-button>
          </el-badge>
        </div>
      </el-card>
    </el-row>
      <saleordermstlistson></saleordermstlistson>
    <router-view></router-view>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import request from "@/utils/request";
import {
  getAll,
  getOne,
  create,
  update,
  deleteBatch
} from "@/api/sale/saleOrderMst";
import moment from "moment";
import saleordermstlistson from '@/views/sale/SaleOrderMstListSon.vue';

export default {
  components: { Pagination,saleordermstlistson },
  data() {
    return {
      filterText: "",
      data2: [],
      defaultProps: {
        children: "children",
        label: "SaleOrderMst"
      },
      list: null,
      list2: null,
      listLoading: true,
      total: 0,
      total2: 0,
      listQuery: {
        page: 1,
        limit: 6,
        pageSizes: [6, 10, 14]
      },
      listQuery2: {
        page: 1,
        limit: 6,
        pageSizes: [6, 10, 14]
      },
      currentSaleOrderMstId: 0,
      dialogFormVisible: false,
      dialogStatus: "",
      textMap: {
        update: "编辑",
        create: "创建"
      },
      rules: {
        orderno: [
          {
            required: true,
            message: "orderno不能为空！",
            trigger: "change"
          }
        ],
        sbillname: [
          {
            required: true,
            message: "sbillname不能为空！",
            trigger: "change"
          }
        ],
        scontractno: [
          {
            required: true,
            message: "scontractno不能为空！",
            trigger: "change"
          }
        ],
        ssalesid: [
          {
            required: true,
            message: "ssalesid不能为空！",
            trigger: "change"
          }
        ],
        dorderdate: [
          {
            required: true,
            message: "dorderdate不能为空！",
            trigger: "change"
          }
        ],
        icustomerid: [
          {
            required: true,
            message: "icustomerid不能为空！",
            trigger: "change"
          }
        ],
        sproductserial: [
          {
            required: true,
            message: "sproductserial不能为空！",
            trigger: "change"
          }
        ],
        sseasoncode: [
          {
            required: true,
            message: "sseasoncode不能为空！",
            trigger: "change"
          }
        ],
        sprocesstypecode: [
          {
            required: true,
            message: "sprocesstypecode不能为空！",
            trigger: "change"
          }
        ],
        spaytermcode: [
          {
            required: true,
            message: "spaytermcode不能为空！",
            trigger: "change"
          }
        ],
        ncommissionrate: [
          {
            required: true,
            message: "ncommissionrate不能为空！",
            trigger: "change"
          }
        ],
        sremark: [
          {
            required: true,
            message: "sremark不能为空！",
            trigger: "change"
          }
        ],
        istatus: [
          {
            required: true,
            message: "istatus不能为空！",
            trigger: "change"
          }
        ],
        iversion: [
          {
            required: true,
            message: "iversion不能为空！",
            trigger: "change"
          }
        ],
        screator: [
          {
            required: true,
            message: "screator不能为空！",
            trigger: "change"
          }
        ],
        dcreatedate: [
          {
            required: true,
            message: "dcreatedate不能为空！",
            trigger: "change"
          }
        ],
        sdeptno: [
          {
            required: true,
            message: "sdeptno不能为空！",
            trigger: "change"
          }
        ],
        sapprover: [
          {
            required: true,
            message: "sapprover不能为空！",
            trigger: "change"
          }
        ],
        dapproveddate: [
          {
            required: true,
            message: "dapproveddate不能为空！",
            trigger: "change"
          }
        ],
        scontractremark: [
          {
            required: true,
            message: "scontractremark不能为空！",
            trigger: "change"
          }
        ],
        sartuser: [
          {
            required: true,
            message: "sartuser不能为空！",
            trigger: "change"
          }
        ],
        dartreceiveddate: [
          {
            required: true,
            message: "dartreceiveddate不能为空！",
            trigger: "change"
          }
        ],
        bartfinished: [
          {
            required: true,
            message: "bartfinished不能为空！",
            trigger: "change"
          }
        ],
        sordertype: [
          {
            required: true,
            message: "sordertype不能为空！",
            trigger: "change"
          }
        ],
        iproducestatus: [
          {
            required: true,
            message: "iproducestatus不能为空！",
            trigger: "change"
          }
        ],
        iprocessfactoryid: [
          {
            required: true,
            message: "iprocessfactoryid不能为空！",
            trigger: "change"
          }
        ],
        srefstyleno: [
          {
            required: true,
            message: "srefstyleno不能为空！",
            trigger: "change"
          }
        ],
        srefcustpono: [
          {
            required: true,
            message: "srefcustpono不能为空！",
            trigger: "change"
          }
        ],
        drefdeliverydate: [
          {
            required: true,
            message: "drefdeliverydate不能为空！",
            trigger: "change"
          }
        ],
        itotalqty: [
          {
            required: true,
            message: "itotalqty不能为空！",
            trigger: "change"
          }
        ],
        iagentid: [
          {
            required: true,
            message: "iagentid不能为空！",
            trigger: "change"
          }
        ],
        sorgorderno: [
          {
            required: true,
            message: "sorgorderno不能为空！",
            trigger: "change"
          }
        ],
        srefcustlotstyleno: [
          {
            required: true,
            message: "srefcustlotstyleno不能为空！",
            trigger: "change"
          }
        ],
        ipaymentday: [
          {
            required: true,
            message: "ipaymentday不能为空！",
            trigger: "change"
          }
        ],
        imanagecompany: [
          {
            required: true,
            message: "imanagecompany不能为空！",
            trigger: "change"
          }
        ],
        scustdeptid: [
          {
            required: true,
            message: "scustdeptid不能为空！",
            trigger: "change"
          }
        ],
        scustman: [
          {
            required: true,
            message: "scustman不能为空！",
            trigger: "change"
          }
        ],
        swashid: [
          {
            required: true,
            message: "swashid不能为空！",
            trigger: "change"
          }
        ],
        ideclfactid: [
          {
            required: true,
            message: "ideclfactid不能为空！",
            trigger: "change"
          }
        ],
        iproductfactid: [
          {
            required: true,
            message: "iproductfactid不能为空！",
            trigger: "change"
          }
        ],
        bcomplete: [
          {
            required: true,
            message: "bcomplete不能为空！",
            trigger: "change"
          }
        ],
        spricetype: [
          {
            required: true,
            message: "spricetype不能为空！",
            trigger: "change"
          }
        ],
        ssalestype: [
          {
            required: true,
            message: "ssalestype不能为空！",
            trigger: "change"
          }
        ],
        sproducestatususerid: [
          {
            required: true,
            message: "sproducestatususerid不能为空！",
            trigger: "change"
          }
        ],
        dcompletedate: [
          {
            required: true,
            message: "dcompletedate不能为空！",
            trigger: "change"
          }
        ],
        scompleteperson: [
          {
            required: true,
            message: "scompleteperson不能为空！",
            trigger: "change"
          }
        ],
        scancelproductuserid: [
          {
            required: true,
            message: "scancelproductuserid不能为空！",
            trigger: "change"
          }
        ],
        dcancelproductdate: [
          {
            required: true,
            message: "dcancelproductdate不能为空！",
            trigger: "change"
          }
        ],
        sexportsalesno: [
          {
            required: true,
            message: "sexportsalesno不能为空！",
            trigger: "change"
          }
        ],
        simportorderno: [
          {
            required: true,
            message: "simportorderno不能为空！",
            trigger: "change"
          }
        ],
        dproducedate: [
          {
            required: true,
            message: "dproducedate不能为空！",
            trigger: "change"
          }
        ],
        sordertypecode: [
          {
            required: true,
            message: "sordertypecode不能为空！",
            trigger: "change"
          }
        ],
        sproducestatususername: [
          {
            required: true,
            message: "sproducestatususername不能为空！",
            trigger: "change"
          }
        ],
        scustsubdept: [
          {
            required: true,
            message: "scustsubdept不能为空！",
            trigger: "change"
          }
        ]
      },
      temp: {
        id: undefined,
        orderno: "",
        sbillname: "",
        scontractno: "",
        ssalesid: "",
        dorderdate: "",
        icustomerid: "",
        sproductserial: "",
        sseasoncode: "",
        sprocesstypecode: "",
        spaytermcode: "",
        ncommissionrate: "",
        sremark: "",
        istatus: "",
        iversion: "",
        screator: "",
        dcreatedate: "",
        sdeptno: "",
        sapprover: "",
        dapproveddate: "",
        scontractremark: "",
        sartuser: "",
        dartreceiveddate: "",
        bartfinished: "",
        sordertype: "",
        iproducestatus: "",
        iprocessfactoryid: "",
        srefstyleno: "",
        srefcustpono: "",
        drefdeliverydate: "",
        itotalqty: "",
        iagentid: "",
        sorgorderno: "",
        srefcustlotstyleno: "",
        ipaymentday: "",
        imanagecompany: "",
        scustdeptid: "",
        scustman: "",
        swashid: "",
        ideclfactid: "",
        iproductfactid: "",
        bcomplete: "",
        spricetype: "",
        ssalestype: "",
        sproducestatususerid: "",
        dcompletedate: "",
        scompleteperson: "",
        scancelproductuserid: "",
        dcancelproductdate: "",
        sexportsalesno: "",
        simportorderno: "",
        dproducedate: "",
        sordertypecode: "",
        sproducestatususername: "",
        scustsubdept: ""
      },
      //表格變量
      lstSelected: [],
     
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val);
    }
  },
  created() {
    this.fetchData();
  },
  methods: {
    handleSelectionChange(val) {
      this.lstSelected = val;
    },
    fetchData() {
      this.listLoading = true;
      let params = {
        name: ""
      };
      getAll(params).then(response => {
        this.list = response.data;
        this.listLoading = false;
      });
    },

    rowClick(row, column, event) {
      this.currentTherbligsTypeId = row.id;
      //this.getTherbligs()
    },
    ui_create() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.temp.id = 0; //自增
          create(this.temp).then(() => {
            this.list.unshift(this.temp);
            this.dialogFormVisible = false;
            this.$notify({
              title: "Success",
              message: "添加成功！",
              type: "success",
              duration: 2000
            });
          });
        }
      });
    },
    ui_update() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          update(this.temp).then(() => {
            const index = this.list.findIndex(v => v.id === this.temp.id);
            this.list.splice(index, 1, this.temp);
            this.dialogFormVisible = false;
            this.$notify({
              title: "Success",
              message: "修改成功！",
              type: "success",
              duration: 2000
            });
          });
        }
      });
    },
    ui_delete(row, index) {
      if (this.lstSelected == null || this.lstSelected.length === 0) {
        this.$message.error("请先选择要删除的SaleOrderMst");
        return;
      }
      let ids = [];
      this.lstSelected.map(function(elm) {
        ids.push(elm.id);
      });
      debugger;
      deleteBatch(ids).then(() => {
        ids.forEach(elm => {
          const index = this.list.findIndex(v => v.id === elm);
          this.list.splice(index, 1);
        });

        this.dialogFormVisible = false;
        this.$notify({
          title: "Success",
          message: "删除成功！",
          type: "success",
          duration: 2000
        });
      });
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        orderno: "",
        sbillname: "",
        scontractno: "",
        ssalesid: "",
        dorderdate: "",
        icustomerid: "",
        sproductserial: "",
        sseasoncode: "",
        sprocesstypecode: "",
        spaytermcode: "",
        ncommissionrate: "",
        sremark: "",
        istatus: "",
        iversion: "",
        screator: "",
        dcreatedate: "",
        sdeptno: "",
        sapprover: "",
        dapproveddate: "",
        scontractremark: "",
        sartuser: "",
        dartreceiveddate: "",
        bartfinished: "",
        sordertype: "",
        iproducestatus: "",
        iprocessfactoryid: "",
        srefstyleno: "",
        srefcustpono: "",
        drefdeliverydate: "",
        itotalqty: "",
        iagentid: "",
        sorgorderno: "",
        srefcustlotstyleno: "",
        ipaymentday: "",
        imanagecompany: "",
        scustdeptid: "",
        scustman: "",
        swashid: "",
        ideclfactid: "",
        iproductfactid: "",
        bcomplete: "",
        spricetype: "",
        ssalestype: "",
        sproducestatususerid: "",
        dcompletedate: "",
        scompleteperson: "",
        scancelproductuserid: "",
        dcancelproductdate: "",
        sexportsalesno: "",
        simportorderno: "",
        dproducedate: "",
        sordertypecode: "",
        sproducestatususername: "",
        scustsubdept: ""
      };
    },
    handleCreate() {
      this.resetTemp();
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleUpdate() {
      if (this.lstSelected == null || this.lstSelected.length !== 1) {
        this.$message.error("请先选择一条SaleOrderMst");
        return;
      }
      this.temp = Object.assign({}, this.lstSelected[0]); // copy obj
      this.dialogStatus = "update";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    
  }
};
</script>
<style scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.wapper {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

/deep/ .el-table .el-table__fixed {
    height:auto !important; 
    bottom:16px; 
}
</style>
